/**************************************************************
  > File Name: 167.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年02月11日 星期五 08时02分41秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>

int* twoSum(int* numbers, int numbersSize, int target, int* returnSize)
{
	int left = 0;	
	int right = numbersSize - 1;
	int *retArray = (int *)calloc(2, sizeof(int));

	while (left <= right)
	{
		if (numbers[left] + numbers[right] == target)
		{
			retArray[0] = left + 1;
			retArray[1] = right + 1;
			*returnSize = 2;
			return retArray;
		}

		if (numbers[left] + numbers[right] < target)
		{
			left++;	
		}
		else
		{
			right--;	
		}	
	}
}

int main(int argc, char **argv)
{
	int arr[] = {2,7,11,15};
	int target = 9;
	int returnSize = 0;
	int *ret;

	ret = twoSum(arr, sizeof(arr) / sizeof(*arr), target, &returnSize);
	for (int i = 0; i < returnSize; i++)
	{
		printf("%d,",ret[i]);
	}

    exit(0);
}
